package iha.standard;

import iha.framework.*;
import java.util.*;

import org.junit.*;
import static org.junit.Assert.*;

public class ItemCacheMock1 implements IItemCache
{
    private boolean success = true;
    private boolean c_lookup = false;
    private boolean c_add = false;
    private boolean c_remove = false;

    private IItem i;

    public LinkedList<IItem> LookUpItem(final long partnumber, final String description)
    {
	if (c_lookup)
	    success = false;
	    
	c_lookup = true;


	this.i = new IItem()
	{
	    public int getSubSupplier(){return 0;}
	    public void setSubSupplier(int supplier){}
	    
	    public long getPartNumber(){return partnumber;}
	    public void setPartNumber(long number){}
	    
	    public String getDescription(){return description;}
	    public void setDescription(String description){}
	    
	    public Date getHit(){return new Date(0);}  //trivially too old item :))
	    public void setHit(Date date){}
	};

	LinkedList<IItem> llist = new LinkedList<IItem>();
	llist.add(i);

	return llist;
    }

    public void AddItems(LinkedList<IItem> items)
    {
	if ( (!c_lookup) || c_add)
	     success = false;

	c_add = true;
    }

    public void RemoveItems(LinkedList<IItem> items)
    {
	if ( (!c_lookup) || c_remove)
	    success  = false;

	c_remove = true;

	boolean found = false;
	for (IItem i : items)
	    found |= (i == this.i);
	
	success &= found;
	
    }

    public boolean success()
    {
	if (!success)
	    return false;
	else
	    return (c_lookup && c_add && c_remove);
    }
}
